import React, { Component } from 'react'
import {useState} from "react"
function App () {
    let [val,setVal] = useState("")
    let [arr,setArr] = useState(["111","222","33333"])
    let changVal =(e)=>{
        console.log(e.target.value);
        setVal(e.target.value)
       
    }
    let btnclick = ()=> {
        console.log(val);
        let newArr = [...arr]
        newArr.push(val)
        setArr(newArr)
    }
    let delfn = (index)=>{
       let newarr = [...arr]
       newarr.splice(index,1)
       setArr( newarr)
    }
    return (
        <div>
            <input type="text" value={val} onChange={(e)=>{changVal(e)}}/> <button onClick={btnclick}>点击</button>
            <div>
                {
                    arr && arr.length ? arr.map((item,index)=>{
                        return <li key={index}><span onClick={()=>{delfn(index)}}>{item}</span> <b>x</b></li>
                    }):""
                }
            </div>
        </div>
    )
}

export default App